# coding=utf-8
"""
Copyright 2019-2020 Fang Jin Biao

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""

# @Time    : 2020/6/13 13:43
# @Author  : Fang Jin Biao
# @Email   : 215466914@qq.com
# @File    : user_api.py
# @Project : SnowAdminWeb

import json
import os
from collections import OrderedDict
from io import SEEK_END

import bcrypt
from flask import request, Blueprint, session,g
from flask_restful import Api, marshal_with, Resource, inputs
from flask_restful.reqparse import RequestParser
from werkzeug.utils import secure_filename

from webapp.config import ServerConfig, api_utils
from webapp.config.api_utils import build_params, oper_log, check_auth, datetime_parse
from webapp.dto_mapper import user_page_fields, user_edit_fields
from webapp.extensions import AppException
from webapp.models import redis_client, db
from webapp.schema import UserSchema,UserGuideSchema
from webapp.service.sys_service import UserService, DataService, DeptService, RoleService
from webapp.tools import decrypt_by_private_key, check_password, download_excel, format_date

user_guide_app = Blueprint('user_guide', __name__, url_prefix='/api/userGuide')
user_guide_api = Api(user_guide_app)
import time


parser = RequestParser()
parser.add_argument('user_guide', location='json', type=str, trim=True, required=True)


@user_guide_api.resource('/add',methods=['POST'])
class userGuideAdd(Resource):
    @oper_log('增加导航浏览标记', request)
    def post(self):
        user = json.loads(g.get("user"))
        params = request.get_json()
        print("params:::::::::::",params)
        schema = UserGuideSchema()
        userGuide = schema.load(params, unknown="exclude")
        userGuide.user_id = user["id"]
        db.session.add(userGuide)

        db.session.flush()
        db.session.commit()
        return '添加成功'